<template>
    <div class="ns-diy">
        <el-carousel v-loading="loadingAd" class="adv-el-carousel" :height="dataHeight">
            <el-carousel-item v-for="item in adList" :key="item.adv_id">
                <el-image :src="$img(item.adv_image)" @click="$router.pushToTab(item.adv_url.url)" style="width:100%" fit="scaledown" />
            </el-carousel-item>
        </el-carousel>
       
       
        <!-- 楼层区 -->
        <div class="content-div">
            <div class="floor">
                <div v-for="(item, index) in floorList" :key="index" class="floor_item">
                    <floor-style-1 v-if="item.block_name == 'floor-style-1'" :data="item" />
                    <floor-style-2 v-if="item.block_name == 'floor-style-2'" :data="item" />
                    <floor-style-3 v-if="item.block_name == 'floor-style-3'" :data="item" />
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import { brandList } from "@/api/goods/goods"
import { mapGetters } from "vuex"
import { adList } from "@/api/website"
import floorStyle1 from '../index/components/floor-style-1'
import floorStyle2 from '../index/components/floor-style-2'
import floorStyle3 from '../index/components/floor-style-3'
import {floors} from "@/api/pc"




export default {
    name: "brand",
    components: {
        floorStyle1,
        floorStyle2,
        floorStyle3,
    },
    data: () => {
        return {
            total: 0,
            currentPage: 1,
            pageSize: 20,
            brandList: [],
            siteId: 0,
            loading: true,
            loadingAd: true,
            adList: [],
            adv_position: [],
            //楼层区
            floorList: [],
            viewName:'',
            dataHeight: '',
        }
    },
    mounted() {

    },
    created() {
        this.viewName = this.$route.query.view_name;
        this.getAdList()
        this.getBrandList()
        this.getFloors()





        
    },
    computed: {
        ...mapGetters(["defaultGoodsImage"])
    },
    methods: {

        getFloors() {
            floors({view_name : this.viewName})
                .then(res => {
                    this.floorList = res.data;
                })
                .catch(err => {
                    console.log(err)
                })
        },
        handlePageSizeChange(size) {
            this.pageSize = size
            this.refresh()
        },
        handleCurrentPageChange(page) {
            this.currentPage = page
            this.refresh()
        },
        refresh() {
            this.loading = true
            this.getBrandList()
        },
        getBrandList() {
            brandList({
                page_size: this.pageSize,
                page: this.currentPage,
                site_id: this.siteId
            })
                .then((res) => {
                    this.brandList = res.data.list
                    this.total = res.data.count
                    this.loading = false
                })
                .catch((err) => {
                    this.loading = false
                    this.$message.error(err.message)
                })
        },
        /**
         * 图片加载失败
         */
        imageError(index) {
            this.brandList[index].image_url = this.defaultGoodsImage
        },
        getAdList() {
            //记得改自定义图片搜索关键字
            adList({ keyword: this.viewName })
                .then((res) => {
                    this.adList = res.data.adv_list;
                    this.adv_position = res.data.adv_position;
                    this.dataHeight = this.adv_position.ap_height + 'px';
                    //console.log(this.adv_position,'ssss');

                    for (let i = 0; i < this.adList.length; i++) {
                        if (this.adList[i].adv_url) this.adList[i].adv_url = JSON.parse(this.adList[i].adv_url)
                    }
                    this.loadingAd = false
                })
                .catch((err) => {
                    this.loadingAd = false
                })
        }
    }
}



</script>
<style lang="scss" scoped>

.floor {
    width: $width;
    margin: 20px auto;
    .floor_item {
        margin-top: 10px;
    }
}
.ns-text-align {
    text-align: center;
}

.ns-brand-box {
    width: 100%;
    background: #ffffff;
    > div {
        width: $width;
        margin: 0 auto;
    }
}
.ns-brand-title-wrap {
    padding-top: 54px;
    .ns-brand-title {
        font-size: 26px;
        font-weight: 600;
        line-height: 30px;
    }
    .ns-brand-en {
        font-size: 24px;
        font-weight: 600;
        color: #383838;
        opacity: 0.2;
        text-transform: uppercase;
        letter-spacing: 5px;
        line-height: 30px;
    }
}
.ns-brand-list {
    display: flex;
    flex-wrap: wrap;
    padding-top: 30px;

    .ns-brand-li {
        width: 20%;
        padding: 8px 6px;
        box-sizing: border-box;

        .ns-brand-wrap {
            width: 100%;
            border: 1px solid #f1f1f1;
            overflow: hidden;
            color: #303133;
            padding: 15px;
            box-sizing: border-box;
            cursor: pointer;
            text-align: center;

            .el-image {
                width: 100%;
                height: 120px;
                line-height: 120px;
            }

            p {
                font-size: 22px;
                color: #383838;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
        }
    }
}

.empty-wrap {
    margin-top: 30px;
}
</style>
<style lang="scss">
.ns-brand {
    .el-carousel {
        .el-image__inner {
            width: auto;
        }
    }
    .el-carousel__arrow--right {
        right: 60px;
    }
}
</style>
